Repository Public
1// UQO Éval — Métré : un objet de plan (mise à jour, suppression).2import { NextRequest, NextResponse } from "next/server";3import { HttpError, handle, readJson, requireProject, requireUser } from "@/lib/metre/auth";4import { deleteObject, getObject, pageProject, updateObject } from "@/lib/metre/plans";56export const runtime = "nodejs";78async function ctxFor(req: NextRequest, id: string) {9 const ctx = requireUser(req, { limit: { key: "object.edit", max: 600, windowMs: 60_000 } });10 const o = getObject(ctx.db, id);11 if (!o) throw new HttpError(404, "Objet introuvable.");12 requireProject(ctx, pageProject(ctx.db, o.pageId)!.projectId, "write");13 return ctx;14}1516export async function PATCH(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {17 return handle(async () => { const { id } = await params; const ctx = await ctxFor(req, id); return NextResponse.json({ object: updateObject(ctx, id, await readJson(req)) }); });18}19export async function DELETE(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {20 return handle(async () => { const { id } = await params; const ctx = await ctxFor(req, id); deleteObject(ctx, id); return NextResponse.json({ ok: true }); });21}22